package com.viser.partyinrs.adapters;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

import com.viser.partyinrs.entities.Grad;
import com.viser.partyinrs.http.HttpDispatcher;

public class GradAdapter extends DataAdapter {
	
	public GradAdapter() {
		dispatcher = new HttpDispatcher();
	}
	
	@SuppressWarnings("finally")
	public ArrayList<Grad> getGradEntities(String upit) {
		ArrayList<Grad> gradovi = new ArrayList<Grad>();
		try
		{
			String httpResponse = dispatcher.getHttpResponse_GET(pageBase+"gradovi_list.php?upit=upit");
			JSONArray gradArray = new JSONArray(httpResponse);
			for(int i=0; i<gradArray.length(); i++)
			{
				JSONObject grad = gradArray.getJSONObject(i);
				Grad g = new Grad();
				g.idGrad = grad.getInt("id_grad");
				g.naziv = grad.getString("naziv");
				g.drzava = grad.getString("drzava");
				gradovi.add(g);
			}
		}
		catch (Exception ex) { }
		finally {
			return gradovi;
		}
	}
	
}
